package com.hyt.it.ogt.kq.common.bm.config;

import okhttp3.ConnectionPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author 朱振宇
 * @since 2023-06-21
 */
@Configuration
public class OkHttpConfig {

    @Value("${okhttp.connectionPool.maxIdleConnections:500}")
    private int maxIdleConnections;

    @Value("${okhttp.connectionPool.keepAliveDuration:10}")
    private long keepAliveDuration;

    @Bean
    public okhttp3.OkHttpClient okHttpClient() {
        return new okhttp3.OkHttpClient.Builder()
                // 设置连接池
                .connectionPool(new ConnectionPool(maxIdleConnections, keepAliveDuration, TimeUnit.SECONDS))
                .build();
    }
}
